<?php
include($modRootPath.'lib/dbaCustomer.o.inc.php');

$cdba = new dbaCustomer($udba);

if (!$usr->checkPermission('mod_banner_customer','u'))
{
    print "<b>Sie haben nicht die entsprechenden Rechte, um die Tabellen einzurichten!</b>";
    exit;
}

switch ($env->getParam('action'))
{
    case 'add':
        if ($check = $cdba->insert($env->getParam('name'),$env->getParam('descr')))
        {
            if ($check==-1) $emsg = "Der verwendete Name existiert bereits!";
        }
        else
        {
            $emsg = "Beim Speichern ist ein Fehler aufgetreten!: ".$udba->getError();
        }
        break;
    case 'del':
        if (!$cdba->delete($env->getParam('id')))
        {
            $emsg = "Beim L&ouml;schen ist ein Fehler aufgetreten!: ".$udba->getError();
        }
        break;
    case 'uform':
        $customer = $cdba->get($env->getParam('id'));
        break;
    case 'update':
        if (!$cdba->update($env->getParam('id'),$env->getParam('name'),$env->getParam('descr')))
        {
            $emsg = "Beim &Auml;ndern ist ein Fehler aufgetreten!: ".$udba->getError();
        }
        break;
}

$customers = $cdba->getall();

?>
<form action="<?=$formaction?>" method="POST" name="dbform">
<input type="hidden" name="action" value="<?=(isset($customer))?'update':'add'?>">
<input type="hidden" name="id" value="<?=$env->getParam('id')?>">
<input type="hidden" name="instance" value="<?=$instance?>">
<input type="hidden" name="module" value="<?=$module?>">
<input type="hidden" name="target" value="<?=$env->getParam('target')?>">
<table border="0" cellpadding="5" cellspacing="0">
<tr>
    <td bgcolor="#3FB2EB" colspan="2"><b>Kunde <?=(isset($customer))?'&auml;ndern':'einf&uuml;gen'?>:</b></td>
</tr>
<tr>
    <td bgcolor="#E0F6FD">Name:</td>
    <td bgcolor="#E0F6FD">
        <input type="text" name="name" size="40" maxlength="255" value="<?php echo (isset($customer['name']))?htmlspecialchars($customer['name']):''?>" />
    </td>
</tr>
<tr>
    <td bgcolor="#E0F6FD">Beschreibung:</td>
    <td bgcolor="#E0F6FD">
        <textarea wrap="off" name="descr" cols="60" rows="10" /><?php echo (isset($customer['descr']))?htmlspecialchars($customer['descr']):''?></textarea>
    </td>
</tr>
<tr>
    <td bgcolor="#E0F6FD" colspan="2" align="center"><input type="submit" class="button" value="<?=(isset($customer))?'&auml;ndern':'einf&uuml;gen'?>" /></td>
</tr>
</table>
</form>
<h3>Kunden:</h3>
<table border="0" cellpadding="5" cellspacing="0" width="100%">
<tr bgcolor="#3FB2EB">
    <td>Name</td>
    <td>Aktionen</td>
</tr>
<?php
for ($i=0;$i<count($customers);$i++):
?>
<tr>
    <td bgcolor="<?=($i%2==0)?'#E0F6FD':'#74DBFC'?>">
    <?=$customers[$i]['name']?></td>
    <td bgcolor="<?=($i%2==0)?'#E0F6FD':'#74DBFC'?>" width="30%">
    <nobr><input type="button" value="&auml;ndern" onClick="location.replace('<?=$scriptname.$env->getParam('target')?>&action=uform&id=<?=$customers[$i]['id']?>')" class="button" /> 
    <input type="button" value="l&ouml;schen" onClick="location.replace('<?=$scriptname.$env->getParam('target')?>&action=del&id=<?=$customers[$i]['id']?>')" class="button" />
    </nobr></td>
</tr>
<?php
endfor;
?>
</table><br />


<script language="javascript">
<!-- 
  document.dbform.name.focus()
<?php
if ($emsg) print "alert('$emsg')\n";
?>
 //-->
</script>
